<?php
include 'MatrixApp.php';

$fileName = 'transitive.txt';
$solution = new MatrixApp();
$solution->init($fileName);
$matrix = $solution->getMatrix();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
	<h1>Advanced Algorithmics</h1>
	<h2>Homework 9 Graphs</h2>
	<div>
		<form action="solution.php" method="get">
			<select name="method">
				<option value="1" <?php if (isset($_GET['method']) && $_GET['method'] == 1): ?>selected="selected"<?php endif; ?>>Naive multiplication</option>
				<option value="2" <?php if (isset($_GET['method']) && $_GET['method'] == 2): ?>selected="selected"<?php endif; ?>>Warshall algorithm</option>
			</select>
			<input type="submit" value="Go" />
		</form>
	</div>
	<?php $numberOfHops = 6; ?>
	
	<?php $warshall = false; 
	if (isset($_GET['method']) && $_GET['method'] == 2) {
		$warshall = true;
	}
	?>
	<?php for ($x = 1; $x <= $numberOfHops; $x++): ?>
		<div class="column">
			<h3><?php echo $x; ?>-hop</h3>
			<?php if ($x > 1) {
				if ($warshall) {
					$newMatrix = $solution->warhsall($newMatrix, $matrix);
				} else {
					$newMatrix = $solution->multiply($newMatrix, $matrix);
				}
			} else {
				$newMatrix = $matrix;
			} ?>
			<table class="matrix">
				<tr>
				<th></th>
					<?php foreach ($newMatrix as $i => $row): ?>
						<th><?php echo $i; ?></th>
					<?php endforeach; ?>
				</tr>
				<?php foreach ($newMatrix as $i => $row): ?>
				<tr>
						<th><?php echo $i; ?></th>
					
					<?php foreach ($row as $j => $col):?>
						<td><?php echo $col; ?></td>
					<?php endforeach; ?>
				</tr>
				<?php endforeach; ?>
			</table>
		</div>
	<?php endfor; ?>
</body>
</html>

